import { create } from 'zustand';
import { createJSONStorage, persist } from 'zustand/middleware';

export interface UserInfo {
    id: number;
    name: string;
    avatar: string;
    token: string;
}

interface UserState {
    token: string | null;
}

interface UserActions {
    setToken: (token: string) => void;
    logout: () => void;
}

export const useUserStore = create<UserState & UserActions>()(
    persist(
        (set) => ({
            token: null,
            setToken: (token) => set({ token }),
            logout: () => set({ token: null }),
        }),
        {
            name: 'user-storage',
            storage: createJSONStorage(() => localStorage),
        }
    )
); 